#include <stdlib.h>
#include <stdio.h>
typedef struct BTNode{
    int data;
    BTNode * left;
    BTNode * right;
}BTNode;
BTNode * CreatBTree(int a[],int n){
    BTNode * root;
    BTNode * c;
    BTNode * pa;
    BTNode * p;
    root=(BTNode *)malloc(sizeof(BTNode));
    root->data=a[0];
    root->left=root->right=NULL;
    for(int i=1;i<n;i++){
        p=(BTNode *)malloc(sizeof(BTNode));
        p->data=a[i];
        p->left=p->right=NULL;
        c=root;
        while(c){
            pa=c;
            if(c->data>p->data)
                c=c->left;
            else
                c=c->right;
        }
        if(p->data<pa->data)
            pa->left=p;
        else
            pa->right=p;
    }
    return root;
}
void Forder(BTNode * root){
    if(root){
        printf("%d\n",root->data);
        Forder(root->left);
        Forder(root->right);
    }
}
void Inorder(BTNode * root){
    if(root){
        Inorder(root->left);
        printf("%5d",root->data);
        Inorder(root->right);
    }
}
void Porder(BTNode * root){
    if(root){
        Inorder(root->left);
        Inorder(root->right);
        printf("%5d",root->data);
    }
}
int main(void){
    int a[9]={6,5,7,9,2,4,3,8,1};
    BTNode * root=CreatBTree(a,9);
    Forder(root);
    Inorder(root);
    Porder(root);
}